package com.lv;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.Collections;

/**
 * Created with IntelliJ IDEA.
 * <p>
 *
 * </p>
 *
 * @Author: 凉薄
 * @Date: 2022/01/06/19:08
 * @Description:
 */
public class FastCode {
    public static void main(String[] args) {
        String property = System.getProperty("user.dir");
        //数据源配置
        //生成数据源配置
        DataSourceConfig.Builder builder = new DataSourceConfig.Builder("jdbc:mysql://81.69.237.173:3306/vue?useSSL=true&useUnicode=true&characterEncoding=utf-8", "root", "qq260778");
        DataSourceConfig dataSource = builder.build();
        //生成自动生成代码对象
        AutoGenerator autoGenerator = new AutoGenerator(dataSource);

        //全局配置
        //创建全局配置对象
        GlobalConfig.Builder gb=new GlobalConfig.Builder();
        GlobalConfig gc = gb.author("凉薄")//设置作者
                .outputDir(property + "/src/main/java")//设置文件输出目录
                .enableSwagger()//自动注解Swagger
                .disableOpenDir()//完成后不打开目录
                .build();
        //添加全局配置对象
        autoGenerator.global(gc);

        //包配置
        PackageConfig.Builder pb=new PackageConfig.Builder();
        PackageConfig pc = pb.parent("com.lv")//创建包的父目录
                .mapper("mapper")//mapper的包名称
                .pathInfo(Collections.singletonMap(OutputFile.mapperXml, property+"/src/main/resources/mapper"))//指定xml文件位置
                .service("service")//service层的包名称
                .entity("entity")//实体类的包名称
                .serviceImpl("service.impl")//服务实现的包名称
                .controller("controller")//控制层的包名称
                .build();
        autoGenerator.packageInfo(pc);


        //策略配置
        StrategyConfig.Builder sb=new StrategyConfig.Builder();
        StrategyConfig sc = sb.addInclude("sys_user","sys_role","sys_menu","sys_role_menu","sys_user_role")
                .addTablePrefix("sys_")
                .entityBuilder()
                .superClass("BaseEntity")
                .addSuperEntityColumns("create_time","update_time","creater_id","status")
                .enableLombok()//启用lombok
//                .enableTableFieldAnnotation()//开启强制注解
                .columnNaming(NamingStrategy.underline_to_camel)//数据列驼峰命名
                .naming(NamingStrategy.underline_to_camel)//表名称驼峰命名
                .controllerBuilder()
                .enableRestStyle()//rest接口
                .superClass("BaseController")
                .serviceBuilder().formatServiceFileName("%sService")
                .build();

        autoGenerator.strategy(sc);

        autoGenerator.execute();
    }
}
